package com.lxk.mall.pms.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.lxk.mall.pms.domain.PmsProductPropertyValue;
import com.lxk.mall.pms.domain.vo.property.PmsProductPropertyValueVo;
import org.dromara.common.core.utils.CollectionUtils;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;

import java.util.*;

/**
 * 商品属性值Mapper接口
 *
 * @author Lion Li
 * @date 2024-06-06
 */
public interface PmsProductPropertyValueMapper extends BaseMapperPlus<PmsProductPropertyValue, PmsProductPropertyValueVo> {

    default List<PmsProductPropertyValue> selectListByPropertyId(Collection<Long> propertyIds) {
        if (CollectionUtils.isAnyEmpty(propertyIds)) {
            return Collections.emptyList();
        }
        LambdaQueryWrapper<PmsProductPropertyValue> lqw = Wrappers.lambdaQuery();
        lqw.in(PmsProductPropertyValue::getPropertyId,propertyIds);
        return selectList(lqw);
    }

    default Integer selectCountByPropertyId(Long propertyId) {
        LambdaQueryWrapper<PmsProductPropertyValue> lqw = Wrappers.lambdaQuery();
        lqw.eq(PmsProductPropertyValue::getPropertyId, propertyId);
        return selectCount(lqw).intValue();
    }

    default PmsProductPropertyValue selectByName(Long propertyId, String name) {
        return selectOne(new LambdaQueryWrapper<PmsProductPropertyValue>()
            .eq(PmsProductPropertyValue::getPropertyId, propertyId)
            .eq(PmsProductPropertyValue::getName, name));
    }}
